package com.moore.controller;

import com.moore.bean.Comment;
import com.moore.dto.ResponseData;
import com.moore.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/get")
    public ResponseData getCommentList(Long communityId, Long candidateId) {
        List<Comment> commentList = commentService.getCommentList(communityId, candidateId);
        return ResponseData.returnList("查询成功",commentList, commentList.size());
    }

    @PostMapping("/add")
    public ResponseData addComment(@RequestBody Comment comment) {
        int result = commentService.addComment(comment);
        if (result > 0) return ResponseData.ok("评论成功");
        return ResponseData.error("评论失败");
    }

    @GetMapping("/delete")
    public ResponseData deleteComment(Long commentId, Long communityId) {
        int result = commentService.deleteComment(commentId, communityId);
        if (result > 0) return ResponseData.ok("评论已删除");
        return ResponseData.error("评论删除失败");
    }
}
